package com.origin.utils

import android.app.Activity

object ScreenAdaptationUtil {
    //设计图宽度默认为500px
    @JvmOverloads
    fun init(activity: Activity, width: Float = 500F) {
        val displayMetrics = activity.resources.displayMetrics
        //系统屏幕密度
        val density = displayMetrics.density
        //系统字体缩放比例
        val scaleDensity = displayMetrics.scaledDensity
        //屏幕密度、字体缩放比例、像素密度
        val currentDensity = displayMetrics.widthPixels / width
        val currentScaleDensity = currentDensity * (scaleDensity / density)
        val currentDensityDpi = (currentDensity * 160).toInt()

        //替换系统值
        val dm = activity.resources.displayMetrics
        dm.density = currentDensity
        dm.scaledDensity = currentScaleDensity
        dm.densityDpi = currentDensityDpi
    }
}